home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / fold-const.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-16  |  47.4 KB  |  1,833 lines

  1. /* Fold a constant sub-tree into a single node for C-compiler
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /*@@ Fix lossage on folding division of big integers.  */
  21.  
  22. /*@@ This file should be rewritten to use an arbitary precision
  23.   @@ representation for "struct tree_int_cst" and "struct tree_real_cst".
  24.   @@ Perhaps the routines could also be used for bc/dc, and made a lib.
  25.   @@ The routines that translate from the ap rep should
  26.   @@ warn if precision et. al. is lost.
  27.   @@ This would also make life easier when this technology is used
  28.   @@ for cross-compilers.  */
  29.  
  30.  
  31. /* There are only two entry points in this file:
  32.    fold and combine.
  33.  
  34.    fold takes a tree as argument and returns a simplified tree.
  35.  
  36.    combine takes a tree code for an arithmetic operation
  37.    and two operands that are trees for constant values
  38.    and returns the result of the specified operation on those values,
  39.    also as a tree.  */
  40.    
  41. #include <stdio.h>
  42. #include <setjmp.h>
  43. #include "config.h"
  44. #include "tree.h"
  45.  
  46. static void lshift_double ();
  47. static void rshift_double ();
  48. static void lrotate_double ();
  49. static void rrotate_double ();
  50.  
  51. /* To do constant folding on INTEGER_CST nodes requires 64-bit arithmetic.
  52.    We do that by representing the 64-bit integer as 8 shorts,
  53.    with only 8 bits stored in each short, as a positive number.  */
  54.  
  55. /* Unpack a 64-bit integer into 8 shorts.
  56.    LOW and HI are the integer, as two `int' pieces.
  57.    SHORTS points to the array of shorts.  */
  58.  
  59. static void
  60. encode (shorts, low, hi)
  61.      short *shorts;
  62.      int low, hi;
  63. {
  64.   shorts[0] = low & 0xff;
  65.   shorts[1] = (low >> 8) & 0xff;
  66.   shorts[2] = (low >> 16) & 0xff;
  67.   shorts[3] = (low >> 24) & 0xff;
  68.   shorts[4] = hi & 0xff;
  69.   shorts[5] = (hi >> 8) & 0xff;
  70.   shorts[6] = (hi >> 16) & 0xff;
  71.   shorts[7] = (hi >> 24) & 0xff;
  72. }
  73.  
  74. /* Pack an array of 8 shorts into a 64-bit integer.
  75.    SHORTS points to the array of shorts.
  76.    The integer is stored into *LOW and *HI as two `int' pieces.  */
  77.  
  78. static void
  79. decode (shorts, low, hi)
  80.      short *shorts;
  81.      int *low, *hi;
  82. {
  83.   *low = (shorts[3] << 24) | (shorts[2] << 16) | (shorts[1] << 8) | shorts[0];
  84.   *hi = (shorts[7] << 24) | (shorts[6] << 16) | (shorts[5] << 8) | shorts[4];
  85. }
  86.  
  87. /* Make the integer constant T valid for its type
  88.    by setting to 0 or 1 all the bits in the constant
  89.    that don't belong in the type.  */
  90.  
  91. static void
  92. force_fit_type (t)
  93.      tree t;
  94. {
  95.   register int prec = TYPE_PRECISION (TREE_TYPE (t));
  96.  
  97.   if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
  98.     prec = BITS_PER_WORD;
  99.  
  100.   /* First clear all bits that are beyond the type's precision.  */
  101.  
  102.   if (prec == 2 * HOST_BITS_PER_INT)
  103.     ;
  104.   else if (prec > HOST_BITS_PER_INT)
  105.     {
  106.       TREE_INT_CST_HIGH (t)
  107.     &= ~((-1) << (prec - HOST_BITS_PER_INT));
  108.     }
  109.   else
  110.     {
  111.       TREE_INT_CST_HIGH (t) = 0;
  112.       if (prec < HOST_BITS_PER_INT)
  113.     TREE_INT_CST_LOW (t)
  114.       &= ~((-1) << prec);
  115.     }
  116.  
  117.   /* If it's a signed type and value's sign bit is set, extend the sign.  */
  118.  
  119.   if (! TREE_UNSIGNED (TREE_TYPE (t))
  120.       && prec != 2 * HOST_BITS_PER_INT
  121.       && (prec > HOST_BITS_PER_INT
  122.       ? TREE_INT_CST_HIGH (t) & (1 << (prec - HOST_BITS_PER_INT - 1))
  123.       : TREE_INT_CST_LOW (t) & (1 << (prec - 1))))
  124.     {
  125.       /* Value is negative:
  126.      set to 1 all the bits that are outside this type's precision.  */
  127.       if (prec > HOST_BITS_PER_INT)
  128.     {
  129.       TREE_INT_CST_HIGH (t)
  130.         |= ((-1) << (prec - HOST_BITS_PER_INT));
  131.     }
  132.       else
  133.     {
  134.       TREE_INT_CST_HIGH (t) = -1;
  135.       if (prec < HOST_BITS_PER_INT)
  136.         TREE_INT_CST_LOW (t)
  137.           |= ((-1) << prec);
  138.     }
  139.     }
  140. }
  141.  
  142. /* Add two 64-bit integers with 64-bit result.
  143.    Each argument is given as two `int' pieces.
  144.    One argument is L1 and H1; the other, L2 and H2.
  145.    The value is stored as two `int' pieces in *LV and *HV.
  146.    We use the 8-shorts representation internally.  */
  147.  
  148. static void
  149. add_double (l1, h1, l2, h2, lv, hv)
  150.      int l1, h1, l2, h2;
  151.      int *lv, *hv;
  152. {
  153.   short arg1[8];
  154.   short arg2[8];
  155.   register int carry = 0;
  156.   register int i;
  157.  
  158.   encode (arg1, l1, h1);
  159.   encode (arg2, l2, h2);
  160.  
  161.   for (i = 0; i < 8; i++)
  162.     {
  163.       carry += arg1[i] + arg2[i];
  164.       arg1[i] = carry & 0xff;
  165.       carry >>= 8;
  166.     }
  167.  
  168.   decode (arg1, lv, hv);
  169. }
  170.  
  171. /* Negate a 64-bit integers with 64-bit result.
  172.    The argument is given as two `int' pieces in L1 and H1.
  173.    The value is stored as two `int' pieces in *LV and *HV.
  174.    We use the 8-shorts representation internally.  */
  175.  
  176. static void
  177. neg_double (l1, h1, lv, hv)
  178.      int l1, h1;
  179.      int *lv, *hv;
  180. {
  181.   if (l1 == 0)
  182.     {
  183.       *lv = 0;
  184.       *hv = - h1;
  185.     }
  186.   else
  187.     {
  188.       *lv = - l1;
  189.       *hv = ~ h1;
  190.     }
  191. }
  192.  
  193. /* Multiply two 64-bit integers with 64-bit result.
  194.    Each argument is given as two `int' pieces.
  195.    One argument is L1 and H1; the other, L2 and H2.
  196.    The value is stored as two `int' pieces in *LV and *HV.
  197.    We use the 8-shorts representation internally.  */
  198.  
  199. static void
  200. mul_double (l1, h1, l2, h2, lv, hv)
  201.      int l1, h1, l2, h2;
  202.      int *lv, *hv;
  203. {
  204.   short arg1[8];
  205.   short arg2[8];
  206.   short prod[16];
  207.   register int carry = 0;
  208.   register int i, j, k;
  209.  
  210.   /* These two cases are used extensively, arising from pointer
  211.      combinations.  */
  212.   if (h2 == 0)
  213.     {
  214.       if (l2 == 2)
  215.     {
  216.       unsigned temp = l1 + l1;
  217.       *hv = h1 * 2 + (temp < l1);
  218.       *lv = temp;
  219.       return;
  220.     }
  221.       if (l2 == 4)
  222.     {
  223.       unsigned temp = l1 + l1;
  224.       h1 = h1 * 4 + (temp < l1) << 1;
  225.       l1 = temp;
  226.       temp += temp;
  227.       h1 += (temp < l1);
  228.       *lv = temp;
  229.       *hv = h1;
  230.       return;
  231.     }
  232.       if (l2 == 8)
  233.     {
  234.       unsigned temp = l1 + l1;
  235.       h1 = h1 * 8 + (temp < l1) << 2;
  236.       l1 = temp;
  237.       temp += temp;
  238.       h1 += (temp < l1) << 1;
  239.       l1 = temp;
  240.       temp += temp;
  241.       h1 += (temp < l1);
  242.       *lv = temp;
  243.       *hv = h1;
  244.       return;
  245.     }
  246.     }
  247.  
  248.   encode (arg1, l1, h1);
  249.   encode (arg2, l2, h2);
  250.  
  251.   bzero (prod, sizeof prod);
  252.  
  253.   for (i = 0; i < 8; i++)
  254.     for (j = 0; j < 8; j++)
  255.       {
  256.     k = i + j;
  257.     carry = arg1[i] * arg2[j];
  258.     while (carry)
  259.       {
  260.         carry += prod[k];
  261.         prod[k] = carry & 0xff;
  262.         carry >>= 8;
  263.         k++;
  264.       }
  265.       }
  266.  
  267.   decode (prod, lv, hv);    /* @@decode ignores prod[8] -> prod[15] */
  268. }
  269.  
  270. /* Shift the 64-bit integer in L1, H1 left by COUNT places
  271.    keeping only PREC bits of result.
  272.    Shift right if COUNT is negative.
  273.    ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
  274.    Store the value as two `int' pieces in *LV and *HV.  */
  275.  
  276. static void
  277. lshift_double (l1, h1, count, prec, lv, hv, arith)
  278.      int l1, h1, count, prec;
  279.      int *lv, *hv;
  280.      int arith;
  281. {
  282.   short arg1[8];
  283.   register int i;
  284.   register int carry;
  285.  
  286.   if (count < 0)
  287.     {
  288.       rshift_double (l1, h1, - count, prec, lv, hv, arith);
  289.       return;
  290.     }
  291.  
  292.   encode (arg1, l1, h1);
  293.  
  294.   if (count > prec)
  295.     count = prec;
  296.  
  297.   while (count > 0)
  298.     {
  299.       carry = 0;
  300.       for (i = 0; i < 8; i++)
  301.     {
  302.       carry += arg1[i] << 1;
  303.       arg1[i] = carry & 0xff;
  304.       carry >>= 8;
  305.     }
  306.       count--;
  307.     }
  308.  
  309.   decode (arg1, lv, hv);
  310. }
  311.  
  312. /* Shift the 64-bit integer in L1, H1 right by COUNT places
  313.    keeping only PREC bits of result.  COUNT must be positive.
  314.    ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
  315.    Store the value as two `int' pieces in *LV and *HV.  */
  316.  
  317. static void
  318. rshift_double (l1, h1, count, prec, lv, hv, arith)
  319.      int l1, h1, count, prec;
  320.      int *lv, *hv;
  321.      int arith;
  322. {
  323.   short arg1[8];
  324.   register int i;
  325.   register int carry;
  326.  
  327.   encode (arg1, l1, h1);
  328.  
  329.   if (count > prec)
  330.     count = prec;
  331.  
  332.   carry = arith && arg1[7] >> 7;
  333.   while (count > 0)
  334.     {
  335.       for (i = 7; i >= 0; i--)
  336.     {
  337.       carry <<= 8;
  338.       carry += arg1[i];
  339.       arg1[i] = (carry >> 1) & 0xff;
  340.     }
  341.       count--;
  342.     }
  343.  
  344.   decode (arg1, lv, hv);
  345. }
  346.  
  347. /* Rotate the 64-bit integer in L1, H1 left by COUNT places
  348.    keeping only PREC bits of result.
  349.    Rotate right if COUNT is negative.
  350.    Store the value as two `int' pieces in *LV and *HV.  */
  351.  
  352. static void
  353. lrotate_double (l1, h1, count, prec, lv, hv)
  354.      int l1, h1, count, prec;
  355.      int *lv, *hv;
  356. {
  357.   short arg1[8];
  358.   register int i;
  359.   register int carry;
  360.  
  361.   if (count < 0)
  362.     {
  363.       rrotate_double (l1, h1, - count, prec, lv, hv);
  364.       return;
  365.     }
  366.  
  367.   encode (arg1, l1, h1);
  368.  
  369.   if (count > prec)
  370.     count = prec;
  371.  
  372.   carry = arg1[7] >> 7;
  373.   while (count > 0)
  374.     {
  375.       for (i = 0; i < 8; i++)
  376.     {
  377.       carry += arg1[i] << 1;
  378.       arg1[i] = carry & 0xff;
  379.       carry >>= 8;
  380.     }
  381.       count--;
  382.     }
  383.  
  384.   decode (arg1, lv, hv);
  385. }
  386.  
  387. /* Rotate the 64-bit integer in L1, H1 left by COUNT places
  388.    keeping only PREC bits of result.  COUNT must be positive.
  389.    Store the value as two `int' pieces in *LV and *HV.  */
  390.  
  391. static void
  392. rrotate_double (l1, h1, count, prec, lv, hv)
  393.      int l1, h1, count, prec;
  394.      int *lv, *hv;
  395. {
  396.   short arg1[8];
  397.   register int i;
  398.   register int carry;
  399.  
  400.   encode (arg1, l1, h1);
  401.  
  402.   if (count > prec)
  403.     count = prec;
  404.  
  405.   carry = arg1[0] & 1;
  406.   while (count > 0)
  407.     {
  408.       for (i = 7; i >= 0; i--)
  409.     {
  410.       carry <<= 8;
  411.       carry += arg1[i];
  412.       arg1[i] = (carry >> 1) & 0xff;
  413.     }
  414.       count--;
  415.     }
  416.  
  417.   decode (arg1, lv, hv);
  418. }
  419.  
  420. /* Divide 64 bit integer LNUM, HNUM by 64 bit integer LDEN, HDEN
  421.    for a quotient (stored in *LQUO, *HQUO) and remainder (in *LREM, *HREM).
  422.    CODE is a tree code for a kind of division, one of
  423.    TRUNC_DIV_EXPR, FLOOR_DIV_EXPR, CEIL_DIV_EXPR, ROUND_DIV_EXPR
  424.    or EXACT_DIV_EXPR
  425.    It controls how the quotient is rounded to a integer.
  426.    UNS nonzero says do unsigned division.  */
  427.  
  428. static void
  429. div_and_round_double (code, uns,
  430.               lnum_orig, hnum_orig, lden_orig, hden_orig,
  431.               lquo, hquo, lrem, hrem)
  432.      enum tree_code code;
  433.      int uns;
  434.      int lnum_orig, hnum_orig;        /* num == numerator == dividend */
  435.      int lden_orig, hden_orig;        /* den == denominator == divisor */
  436.      int *lquo, *hquo, *lrem, *hrem;
  437. {
  438.   int quo_neg = 0;
  439.   short num[9], den[8], quo[8];    /* extra element for scaling.  */
  440.   register int i, j, work;
  441.   register int carry = 0;
  442.   int lnum = lnum_orig, hnum = hnum_orig;
  443.   int lden = lden_orig, hden = hden_orig;
  444.  
  445.   if ((hden == 0) && (lden == 0))
  446.     abort ();
  447.  
  448.   /* calculate quotient sign and convert operands to unsigned.  */
  449.   if (!uns) 
  450.     {
  451.       if (hden < 0) 
  452.     {
  453.       quo_neg = ~ quo_neg;
  454.       neg_double (lden, hden, &lden, &hden);
  455.     }
  456.       if (hnum < 0)
  457.     {
  458.       quo_neg = ~ quo_neg;
  459.       neg_double (lnum, hnum, &lnum, &hnum);
  460.     }
  461.     }
  462.  
  463.   if (hnum == 0 && hden == 0)
  464.     {                /* single precision */
  465.       *hquo = *hrem = 0;
  466.       *lquo = (unsigned) lnum / lden;    /* rounds toward zero since positive args */
  467.       goto finish_up;
  468.     }
  469.  
  470.   if (hnum == 0)
  471.     {                /* trivial case: dividend < divisor */
  472.       /* hden != 0 already checked.  */
  473.       *hquo = *lquo = 0;
  474.       *hrem = hnum;
  475.       *lrem = lnum;
  476.       goto finish_up;
  477.     }
  478.  
  479.   bzero (quo, sizeof quo);
  480.  
  481.   bzero (num, sizeof num);    /* to zero 9th element */
  482.   bzero (den, sizeof den);
  483.  
  484.   encode (num, lnum, hnum); 
  485.   encode (den, lden, hden);
  486.  
  487.   if (hden == 0)
  488.     {                /* simpler algorithm */
  489.       /* hnum != 0 already checked.  */
  490.       for (i = 7; i >= 0; i--)
  491.     {
  492.       work = num[i] + (carry << 8);
  493.       quo[i] = work / lden;
  494.       carry = work % lden;
  495.     }
  496.     }
  497.   else {            /* full double precision,
  498.                    with thanks to Don Knuth's
  499.                    "Semi-Numericial Algorithms".  */
  500. #define BASE 256
  501.     int quo_est, scale, num_hi_sig, den_hi_sig, quo_hi_sig;
  502.  
  503.     /* Find the highest non-zero divisor digit.  */
  504.     for (i = 7; ; i--)
  505.       if (den[i] != 0) {
  506.     den_hi_sig = i;
  507.     break;
  508.       }
  509.     for (i = 7; ; i--)
  510.       if (num[i] != 0) {
  511.     num_hi_sig = i;
  512.     break;
  513.       }
  514.     quo_hi_sig = num_hi_sig - den_hi_sig + 1;
  515.  
  516.     /* Insure that the first digit of the divisor is at least BASE/2.
  517.        This is required by the quotient digit estimation algorithm.  */
  518.  
  519.     scale = BASE / (den[den_hi_sig] + 1);
  520.     if (scale > 1) {        /* scale divisor and dividend */
  521.       carry = 0;
  522.       for (i = 0; i <= 8; i++) {
  523.     work = (num[i] * scale) + carry;
  524.     num[i] = work & 0xff;
  525.     carry = work >> 8;
  526.     if (num[i] != 0) num_hi_sig = i;
  527.       }
  528.       carry = 0;
  529.       for (i = 0; i <= 7; i++) {
  530.     work = (den[i] * scale) + carry;
  531.     den[i] = work & 0xff;
  532.     carry = work >> 8;
  533.     if (den[i] != 0) den_hi_sig = i;
  534.       }
  535.     }
  536.  
  537.     /* Main loop */
  538.     for (i = quo_hi_sig; i > 0; i--) {
  539.       /* quess the next quotient digit, quo_est, by dividing the first
  540.      two remaining dividend digits by the high order quotient digit.
  541.      quo_est is never low and is at most 2 high.  */
  542.  
  543.       int num_hi;        /* index of highest remaining dividend digit */
  544.  
  545.       num_hi = i + den_hi_sig;
  546.  
  547.       work = (num[num_hi] * BASE) + (num_hi ? 0 : num[num_hi - 1]);
  548.       if (num[num_hi] != den[den_hi_sig]) {
  549.     quo_est = work / den[den_hi_sig];
  550.       }
  551.       else {
  552.     quo_est = BASE - 1;
  553.       }
  554.  
  555.       /* refine quo_est so it's usually correct, and at most one high.   */
  556.       while ((den[den_hi_sig - 1] * quo_est)
  557.          > (((work - (quo_est * den[den_hi_sig])) * BASE)
  558.          + ((num_hi - 1) ? 0 : num[num_hi - 2]))) {
  559.     quo_est--;
  560.       }
  561.  
  562.       /* try quo_est as the quotient digit, by multiplying the
  563.          divisor by quo_est and subtracting from the remaining dividend.  */
  564.  
  565.       carry = 0;
  566.  
  567.       for (j = 0; j <= den_hi_sig; j++) {
  568.     int digit;
  569.  
  570.     work = num[i + j] - (quo_est * den[j]) + carry;
  571.     digit = work & 0xff;
  572.     carry = work >> 8;
  573.     if (digit < 0) {
  574.       digit += BASE;
  575.       carry--;
  576.     }
  577.     num[i + j] = digit;
  578.       }
  579.  
  580.       /* if quo_est was high by one, then num[i] went negative and
  581.      we need to correct things.  */
  582.  
  583.       if (num[num_hi] < 0) {
  584.     quo_est--;
  585.     carry = 0;        /* add divisor back in */
  586.     for (j = 0; j <= den_hi_sig; j++) {
  587.       work = num[i + j] + den[j] + carry;
  588.       if (work > BASE) {
  589.         work -= BASE;
  590.         carry = 1;
  591.       }
  592.       else {
  593.         carry = 0;
  594.       }
  595.       num[i + j] = work;
  596.     }
  597.     num [num_hi] += carry;
  598.       }
  599.  
  600.       /* store the quotient digit.  */
  601.       quo[i - 1] = quo_est;
  602.     }
  603.   }
  604.  
  605.   decode (quo, lquo, hquo);
  606.  
  607.  finish_up:
  608.   /* if result is negative, make it so.  */
  609.   if (quo_neg)
  610.     neg_double (*lquo, *hquo, lquo, hquo);
  611.  
  612.   /* compute trial remainder:  rem = num - (quo * den)  */
  613.   mul_double (*lquo, *hquo, lden_orig, hden_orig, lrem, hrem);
  614.   neg_double (*lrem, *hrem, lrem, hrem);
  615.   add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
  616.  
  617.   switch (code)
  618.     {
  619.     case TRUNC_DIV_EXPR:
  620.     case TRUNC_MOD_EXPR:    /* round toward zero */
  621.     case EXACT_DIV_EXPR:    /* for this one, it shouldn't matter */
  622.       return;
  623.  
  624.     case FLOOR_DIV_EXPR:
  625.     case FLOOR_MOD_EXPR:    /* round toward negative infinity */
  626.       if (quo_neg && (*lrem != 0 || *hrem != 0))   /* ratio < 0 && rem != 0 */
  627.     {
  628.       /* quo = quo - 1;  */
  629.       add_double (*lquo, *hquo, -1, -1, lquo, hquo);
  630.     }
  631.       else return;
  632.       break;
  633.  
  634.     case CEIL_DIV_EXPR:
  635.     case CEIL_MOD_EXPR:        /* round toward positive infinity */
  636.       if (!quo_neg && (*lrem != 0 || *hrem != 0))  /* ratio > 0 && rem != 0 */
  637.     {
  638.       add_double (*lquo, *hquo, 1, 0, lquo, hquo);
  639.     }
  640.       else return;
  641.       break;
  642.     
  643.     case ROUND_DIV_EXPR:
  644.     case ROUND_MOD_EXPR:    /* round to closest integer */
  645.       {
  646.     int labs_rem = *lrem, habs_rem = *hrem;
  647.     int labs_den = lden, habs_den = hden, ltwice, htwice;
  648.  
  649.     /* get absolute values */
  650.     if (*hrem < 0) neg_double (*lrem, *hrem, &labs_rem, &habs_rem);
  651.     if (hden < 0) neg_double (lden, hden, &labs_den, &habs_den);
  652.  
  653.     /* if (2 * abs (lrem) >= abs (lden)) */
  654.     mul_double (2, 0, labs_rem, habs_rem, <wice, &htwice);
  655.     if (((unsigned) habs_den < (unsigned) htwice)
  656.         || (((unsigned) habs_den == (unsigned) htwice)
  657.         && ((unsigned) labs_den < (unsigned) ltwice)))
  658.       {
  659.         if (*hquo < 0)
  660.           /* quo = quo - 1;  */
  661.           add_double (*lquo, *hquo, -1, -1, lquo, hquo);
  662.         else
  663.           /* quo = quo + 1; */
  664.           add_double (*lquo, *hquo, 1, 0, lquo, hquo);
  665.       }
  666.     else return;
  667.       }
  668.       break;
  669.  
  670.     default:
  671.       abort ();
  672.     }
  673.  
  674.   /* compute true remainder:  rem = num - (quo * den)  */
  675.   mul_double (*lquo, *hquo, lden_orig, hden_orig, lrem, hrem);
  676.   neg_double (*lrem, *hrem, lrem, hrem);
  677.   add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
  678. }
  679.  
  680. /* Split a tree IN into a constant and a variable part
  681.    that could be combined with CODE to make IN.
  682.    CODE must be a commutative arithmetic operation.
  683.    Store the constant part into *CONP and the variable in &VARP.
  684.    Return 1 if this was done; zero means the tree IN did not decompose
  685.    this way.
  686.  
  687.    If CODE is PLUS_EXPR we also split trees that use MINUS_EXPR.
  688.    Therefore, we must tell the caller whether the variable part
  689.    was subtracted.  We do this by storing 1 or -1 into *VARSIGNP.
  690.    The value stored is the coefficient for the variable term.
  691.    The constant term we return should always be added;
  692.    we negate it if necessary.  */
  693.  
  694. static int
  695. split_tree (in, code, varp, conp, varsignp)
  696.      tree in;
  697.      enum tree_code code;
  698.      tree *varp, *conp;
  699.      int *varsignp;
  700. {
  701.   register tree outtype = TREE_TYPE (in);
  702.   *varp = 0;
  703.   *conp = 0;
  704.  
  705.   /* Strip any conversions that don't change the machine mode.  */
  706.   while ((TREE_CODE (in) == NOP_EXPR
  707.       || TREE_CODE (in) == CONVERT_EXPR)
  708.      && (TYPE_MODE (TREE_TYPE (in))
  709.          == TYPE_MODE (TREE_TYPE (TREE_OPERAND (in, 0)))))
  710.     in = TREE_OPERAND (in, 0);
  711.  
  712.   if (TREE_CODE (in) == code
  713.       || (TREE_CODE (TREE_TYPE (in)) != REAL_TYPE
  714.       /* We can associate addition and subtraction together
  715.          (even though the C standard doesn't say so)
  716.          for integers because the value is not affected.
  717.          For reals, the value might be affected, so we can't.  */
  718.       &&
  719.       ((code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR)
  720.        || (code == MINUS_EXPR && TREE_CODE (in) == PLUS_EXPR))))
  721.     {
  722.       enum tree_code code = TREE_CODE (TREE_OPERAND (in, 0));
  723.       if (code == INTEGER_CST)
  724.     {
  725.       *conp = TREE_OPERAND (in, 0);
  726.       *varp = TREE_OPERAND (in, 1);
  727.       if (TREE_TYPE (*varp) != outtype)
  728.         *varp = convert (outtype, *varp);
  729.       *varsignp = (TREE_CODE (in) == MINUS_EXPR) ? -1 : 1;
  730.       return 1;
  731.     }
  732.       if (TREE_LITERAL (TREE_OPERAND (in, 1)))
  733.     {
  734.       *conp = TREE_OPERAND (in, 1);
  735.       *varp = TREE_OPERAND (in, 0);
  736.       *varsignp = 1;
  737.       if (TREE_TYPE (*varp) != outtype)
  738.         *varp = convert (outtype, *varp);
  739.       if (TREE_CODE (in) == MINUS_EXPR)
  740.         {
  741.           /* If operation is subtraction and constant is second,
  742.          must negate it to get an additive constant.
  743.          And this cannot be done unless it is a manifest constant.
  744.          It could also be the address of a static variable.
  745.          We cannot negate that, so give up.  */
  746.           if (TREE_CODE (*conp) == INTEGER_CST)
  747.         *conp = combine (MINUS_EXPR, integer_zero_node, *conp);
  748.           else
  749.         return 0;
  750.         }
  751.       return 1;
  752.     }
  753.       if (TREE_LITERAL (TREE_OPERAND (in, 0)))
  754.     {
  755.       *conp = TREE_OPERAND (in, 0);
  756.       *varp = TREE_OPERAND (in, 1);
  757.       if (TREE_TYPE (*varp) != outtype)
  758.         *varp = convert (outtype, *varp);
  759.       *varsignp = (TREE_CODE (in) == MINUS_EXPR) ? -1 : 1;
  760.       return 1;
  761.     }
  762.     }
  763.   return 0;
  764. }
  765.  
  766. /* Combine two constants NUM and ARG2 under operation CODE
  767.    to produce a new constant.
  768.    We assume ARG1 and ARG2 have the same data type,
  769.    or at least are the same kind of constant and the same machine mode.  */
  770.  
  771. /* Handle floating overflow for `combine'.  */
  772. static jmp_buf combine_error;
  773.  
  774. tree
  775. combine (code, arg1, arg2)
  776.      enum tree_code code;
  777.      register tree arg1, arg2;
  778. {
  779.   if (TREE_CODE (arg1) == INTEGER_CST)
  780.     {
  781.       register int int1l = TREE_INT_CST_LOW (arg1);
  782.       register int int1h = TREE_INT_CST_HIGH (arg1);
  783.       int int2l = TREE_INT_CST_LOW (arg2);
  784.       int int2h = TREE_INT_CST_HIGH (arg2);
  785.       int low, hi;
  786.       int garbagel, garbageh;
  787.       register tree t;
  788.       int uns = TREE_UNSIGNED (TREE_TYPE (arg1));
  789.  
  790.       switch (code)
  791.     {
  792.     case BIT_IOR_EXPR:
  793.       t = build_int_2 (int1l | int2l, int1h | int2h);
  794.       break;
  795.  
  796.     case BIT_XOR_EXPR:
  797.       t = build_int_2 (int1l ^ int2l, int1h ^ int2h);
  798.       break;
  799.  
  800.     case BIT_AND_EXPR:
  801.       t = build_int_2 (int1l & int2l, int1h & int2h);
  802.       break;
  803.  
  804.     case BIT_ANDTC_EXPR:
  805.       t = build_int_2 (int1l & ~int2l, int1h & ~int2h);
  806.       break;
  807.  
  808.     case RSHIFT_EXPR:
  809.       int2l = - int2l;
  810.     case LSHIFT_EXPR:
  811.       lshift_double (int1l, int1h, int2l,
  812.              TYPE_PRECISION (TREE_TYPE (arg1)),
  813.              &low, &hi,
  814.              !uns);
  815.       t = build_int_2 (low, hi);
  816.       break;
  817.  
  818.     case RROTATE_EXPR:
  819.       int2l = - int2l;
  820.     case LROTATE_EXPR:
  821.       lrotate_double (int1l, int1h, int2l,
  822.               TYPE_PRECISION (TREE_TYPE (arg1)),
  823.               &low, &hi);
  824.       t = build_int_2 (low, hi);
  825.       break;
  826.  
  827.     case PLUS_EXPR:
  828.       if (int1h == 0)
  829.         {
  830.           int2l += int1l;
  831.           if ((unsigned) int2l < int1l)
  832.         int2h += 1;
  833.           t = build_int_2 (int2l, int2h);
  834.           break;
  835.         }
  836.       if (int2h == 0)
  837.         {
  838.           int1l += int2l;
  839.           if ((unsigned) int1l < int2l)
  840.         int1h += 1;
  841.           t = build_int_2 (int1l, int1h);
  842.           break;
  843.         }
  844.       add_double (int1l, int1h, int2l, int2h, &low, &hi);
  845.       t = build_int_2 (low, hi);
  846.       break;
  847.  
  848.     case MINUS_EXPR:
  849.       if (int1h == 0 && int1l == 0)
  850.         {
  851.           t = build_int_2 (- int2l, - int2h - (int2l != 0));
  852.           break;
  853.         }
  854.       if (int2h == 0 && int2l == 0)
  855.         {
  856.           t = build_int_2 (int1l, int1h);
  857.           break;
  858.         }
  859.       neg_double (int2l, int2h, &int2l, &int2h);
  860.       add_double (int1l, int1h, int2l, int2h, &low, &hi);
  861.       t = build_int_2 (low, hi);
  862.       break;
  863.  
  864.     case MULT_EXPR:
  865.   /* Optimize simple cases.  */
  866.       if (int1h == 0)
  867.         {
  868.           unsigned temp;
  869.  
  870.           switch (int1l)
  871.         {
  872.         case 0:
  873.           t = build_int_2 (0, 0);
  874.           goto got_it;
  875.         case 1:
  876.           t = build_int_2 (int2l, int2h);
  877.           goto got_it;
  878.         case 2:
  879.           temp = int2l + int2l;
  880.           int2h = int2h * 2 + (temp < int2l);
  881.           t = build_int_2 (temp, int2h);
  882.           goto got_it;
  883.         case 3:
  884.           temp = int2l + int2l + int2l;
  885.           int2h = int2h * 3 + (temp < int2l);
  886.           t = build_int_2 (temp, int2h);
  887.           goto got_it;
  888.         case 4:
  889.           temp = int2l + int2l;
  890.           int2h = int2h * 4 + (temp < int2l) << 1;
  891.           int2l = temp;
  892.           temp += temp;
  893.           int2h += (temp < int2l);
  894.           t = build_int_2 (temp, int2h);
  895.           goto got_it;
  896.         case 8:
  897.           temp = int2l + int2l;
  898.           int2h = int2h * 8 + (temp < int2l) << 2;
  899.           int2l = temp;
  900.           temp += temp;
  901.           int2h += (temp < int2l) << 1;
  902.           int2l = temp;
  903.           temp += temp;
  904.           int2h += (temp < int2l);
  905.           t = build_int_2 (temp, int2h);
  906.           goto got_it;
  907.         default:
  908.           break;
  909.         }
  910.         }
  911.  
  912.       if (int2h == 0)
  913.         {
  914.           if (int2l == 0)
  915.         {
  916.           t = build_int_2 (0, 0);
  917.           break;
  918.         }
  919.           if (int2l == 1)
  920.         {
  921.           t = build_int_2 (int1l, int1h);
  922.           break;
  923.         }
  924.         }
  925.  
  926.       mul_double (int1l, int1h, int2l, int2h, &low, &hi);
  927.       t = build_int_2 (low, hi);
  928.       break;
  929.  
  930.     case TRUNC_DIV_EXPR: case ROUND_DIV_EXPR: 
  931.     case FLOOR_DIV_EXPR: case CEIL_DIV_EXPR:
  932.     case EXACT_DIV_EXPR:
  933.       if (int2h == 0 && int2l == 1)
  934.         {
  935.           t = build_int_2 (int1l, int1h);
  936.           break;
  937.         }
  938.       if (int1l == int2l && int1h == int2h)
  939.         {
  940.           if ((int1l | int1h) == 0)
  941.         abort ();
  942.           t = build_int_2 (1, 0);
  943.           break;
  944.         }
  945.       div_and_round_double (code, uns, int1l, int1h, int2l, int2h,
  946.                 &low, &hi, &garbagel, &garbageh);
  947.       t = build_int_2 (low, hi);
  948.       break;
  949.  
  950.     case TRUNC_MOD_EXPR: case ROUND_MOD_EXPR: 
  951.     case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
  952.       div_and_round_double (code, uns, int1l, int1h, int2l, int2h,
  953.                 &garbagel, &garbageh, &low, &hi);
  954.       t = build_int_2 (low, hi);
  955.       break;
  956.  
  957.     case MIN_EXPR:
  958.     case MAX_EXPR:
  959.       if (uns)
  960.         {
  961.           low = (((unsigned) int1h < (unsigned) int2h)
  962.              || (((unsigned) int1h == (unsigned) int2h)
  963.              && ((unsigned) int1l < (unsigned) int2l)));
  964.         }
  965.       else
  966.         {
  967.           low = ((int1h < int2h)
  968.              || ((int1h == int2h)
  969.              && ((unsigned) int1l < (unsigned) int2l)));
  970.         }
  971.       if (low == (code == MIN_EXPR))
  972.         t = build_int_2 (int1l, int1h);
  973.       else
  974.         t = build_int_2 (int2l, int2h);
  975.       break;
  976.  
  977.     default:
  978.       abort ();
  979.     }
  980.     got_it:
  981.       TREE_TYPE (t) = TREE_TYPE (arg1);
  982.       force_fit_type (t);
  983.       return t;
  984.     }
  985. #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  986.   if (TREE_CODE (arg1) == REAL_CST)
  987.     {
  988.       register REAL_VALUE_TYPE d1 = TREE_REAL_CST (arg1);
  989.       register REAL_VALUE_TYPE d2 = TREE_REAL_CST (arg2);
  990.       register REAL_VALUE_TYPE value;
  991.  
  992.       if (setjmp (combine_error))
  993.     {
  994.       warning ("floating overflow in constant folding");
  995.       return build (code, TREE_TYPE (arg1), arg1, arg2);
  996.     }
  997.       set_float_handler (combine_error);
  998.  
  999. #ifdef REAL_ARITHMETIC
  1000.       REAL_ARITHMETIC (value, code, d1, d2);
  1001. #else
  1002.       switch (code)
  1003.     {
  1004.     case PLUS_EXPR:
  1005.       value = d1 + d2;
  1006.       break;
  1007.  
  1008.     case MINUS_EXPR:
  1009.       value = d1 - d2;
  1010.       break;
  1011.  
  1012.     case MULT_EXPR:
  1013.       value = d1 * d2;
  1014.       break;
  1015.  
  1016.     case RDIV_EXPR:
  1017.       if (d2 == 0)
  1018.         abort ();
  1019.  
  1020.       value = d1 / d2;
  1021.       break;
  1022.  
  1023.     case MIN_EXPR:
  1024.       value = d1 < d2 ? d1 : d2;
  1025.       break;
  1026.  
  1027.     case MAX_EXPR:
  1028.       value = d1 > d2 ? d1 : d2;
  1029.       break;
  1030.  
  1031.     default:
  1032.       abort ();
  1033.     }
  1034. #endif /* no REAL_ARITHMETIC */
  1035.       set_float_handler (0);
  1036.       return build_real (TREE_TYPE (arg1), value);
  1037.     }
  1038. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1039.   if (TREE_CODE (arg1) == COMPLEX_CST)
  1040.     {
  1041.       register tree r1 = TREE_REALPART (arg1);
  1042.       register tree i1 = TREE_IMAGPART (arg1);
  1043.       register tree r2 = TREE_REALPART (arg2);
  1044.       register tree i2 = TREE_IMAGPART (arg2);
  1045.       register tree t;
  1046.  
  1047.       switch (code)
  1048.     {
  1049.     case PLUS_EXPR:
  1050.       t = build_complex (combine (PLUS_EXPR, r1, r2),
  1051.                  combine (PLUS_EXPR, i1, i2));
  1052.       break;
  1053.  
  1054.     case MINUS_EXPR:
  1055.       t = build_complex (combine (MINUS_EXPR, r1, r2),
  1056.                  combine (MINUS_EXPR, i1, i2));
  1057.       break;
  1058.  
  1059.     case MULT_EXPR:
  1060.       t = build_complex (combine (MINUS_EXPR,
  1061.                       combine (MULT_EXPR, r1, r2),
  1062.                       combine (MULT_EXPR, i1, i2)),
  1063.                  combine (PLUS_EXPR,
  1064.                       combine (MULT_EXPR, r1, i2),
  1065.                       combine (MULT_EXPR, i1, r2)));
  1066.       break;
  1067.  
  1068.     case RDIV_EXPR:
  1069.       {
  1070.         register tree magsquared
  1071.           = combine (PLUS_EXPR,
  1072.              combine (MULT_EXPR, r2, r2),
  1073.              combine (MULT_EXPR, i2, i2));
  1074.         t = build_complex (combine (RDIV_EXPR,
  1075.                     combine (PLUS_EXPR,
  1076.                          combine (MULT_EXPR, r1, r2),
  1077.                          combine (MULT_EXPR, i1, i2)),
  1078.                     magsquared),
  1079.                    combine (RDIV_EXPR,
  1080.                     combine (MINUS_EXPR,
  1081.                          combine (MULT_EXPR, i1, r2),
  1082.                          combine (MULT_EXPR, r1, i2)),
  1083.                     magsquared));
  1084.       }
  1085.       break;
  1086.  
  1087.     default:
  1088.       abort ();
  1089.     }
  1090.       TREE_TYPE (t) = TREE_TYPE (arg1);
  1091.       return t;
  1092.     }
  1093.   return 0;
  1094. }
  1095.  
  1096. /* Given T, a tree representing type conversion of a constant,
  1097.    return a constant tree representing the result of conversion.  */
  1098.  
  1099. static tree
  1100. fold_convert (t)
  1101.      register tree t;
  1102. {
  1103.   register tree arg1 = TREE_OPERAND (t, 0);
  1104.   register tree type = TREE_TYPE (t);
  1105.  
  1106.   if (TREE_CODE (type) == POINTER_TYPE
  1107.       || TREE_CODE (type) == INTEGER_TYPE
  1108.       || TREE_CODE (type) == ENUMERAL_TYPE)
  1109.     {
  1110.       if (TREE_CODE (arg1) == INTEGER_CST)
  1111.     {
  1112.       /* Given an integer constant, make new constant with new type,
  1113.          appropriately sign-extended or truncated.  */
  1114.       t = build_int_2 (TREE_INT_CST_LOW (arg1),
  1115.                TREE_INT_CST_HIGH (arg1));
  1116.       TREE_TYPE (t) = type;
  1117.       force_fit_type (t);
  1118.     }
  1119. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1120.       else if (TREE_CODE (arg1) == REAL_CST)
  1121.     {
  1122.       if (REAL_VALUES_LESS (real_value_from_int_cst (TYPE_MAX_VALUE (type)),
  1123.                 TREE_REAL_CST (arg1))
  1124.           || REAL_VALUES_LESS (TREE_REAL_CST (arg1),
  1125.                    real_value_from_int_cst (TYPE_MIN_VALUE (type))))
  1126.         {
  1127.           warning ("real constant out of range for integer conversion");
  1128.           return t;
  1129.         }
  1130. #ifndef REAL_ARITHMETIC
  1131.       {
  1132.         REAL_VALUE_TYPE d;
  1133.         int low, high;
  1134.         int half_word = 1 << (HOST_BITS_PER_INT / 2);
  1135.  
  1136.         d = TREE_REAL_CST (arg1);
  1137.         if (d < 0)
  1138.           d = -d;
  1139.  
  1140.         high = (int) (d / half_word / half_word);
  1141.         d -= (REAL_VALUE_TYPE) high * half_word * half_word;
  1142.         low = (unsigned) d;
  1143.         if (TREE_REAL_CST (arg1) < 0)
  1144.           neg_double (low, high, &low, &high);
  1145.         t = build_int_2 (low, high);
  1146.       }
  1147. #else
  1148.       {
  1149.         int low, high;
  1150.         REAL_VALUE_TO_INT (low, high, TREE_REAL_CST (arg1));
  1151.         t = build_int_2 (low, high);
  1152.       }
  1153. #endif
  1154.       TREE_TYPE (t) = type;
  1155.       force_fit_type (t);
  1156.     }
  1157. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1158.       TREE_TYPE (t) = type;
  1159.     }
  1160.   else if (TREE_CODE (type) == REAL_TYPE)
  1161.     {
  1162. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1163.       if (TREE_CODE (arg1) == INTEGER_CST)
  1164.     return build_real_from_int_cst (type, arg1);
  1165. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1166.       if (TREE_CODE (arg1) == REAL_CST)
  1167.     return build_real (type, TREE_REAL_CST (arg1));
  1168.     }
  1169.   TREE_LITERAL (t) = 1;
  1170.   return t;
  1171. }
  1172.  
  1173. /* Return nonzero if two constants (that are not manifest constants)
  1174.    are necessarily equal.  It detects only the easiest, common case of
  1175.    equality.  */
  1176.  
  1177. static int
  1178. operand_equal_p (arg0, arg1)
  1179.      tree arg0, arg1;
  1180. {
  1181.   while ((TREE_CODE (arg0) == NOP_EXPR
  1182.       || TREE_CODE (arg0) == CONVERT_EXPR)
  1183.      && TYPE_MODE (TREE_TYPE (arg0)) == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg0, 0))))
  1184.     arg0 = TREE_OPERAND (arg0, 0);
  1185.   while ((TREE_CODE (arg1) == NOP_EXPR
  1186.       || TREE_CODE (arg1) == CONVERT_EXPR)
  1187.      && TYPE_MODE (TREE_TYPE (arg1)) == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg1, 0))))
  1188.     arg1 = TREE_OPERAND (arg1, 0);
  1189.  
  1190.   if (TREE_CODE (arg0) == TREE_CODE (arg1)
  1191.       && TREE_CODE (arg0) == ADDR_EXPR
  1192.       && TREE_OPERAND (arg0, 0) == TREE_OPERAND (arg1, 0))
  1193.     return 1;
  1194.   return 0;
  1195. }
  1196.  
  1197. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1198.  
  1199. /* Return 1 if ARG is a real constant with value zero.
  1200.    This function is not defined in the case where it is impossible
  1201.    to tell whether a real constant is zero (for cross-compilation).  */
  1202.  
  1203. static int
  1204. real_zerop (arg)
  1205.      tree arg;
  1206. {
  1207. #ifdef REAL_IS_NOT_DOUBLE
  1208.   tree t1 = build_real_from_int_cst (TREE_TYPE (arg), integer_zero_node);
  1209.   return REAL_VALUES_EQUAL (TREE_REAL_CST (arg), TREE_REAL_CST (t1));
  1210. #else
  1211.   return TREE_REAL_CST (arg) == 0;
  1212. #endif
  1213. }
  1214. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1215.  
  1216. /* Perform constant folding and related simplification of EXPR.
  1217.    The related simplifications include x*1 => x, x*0 => 0, etc.,
  1218.    and application of the associative law.
  1219.    NOP_EXPR conversions may be removed freely (as long as we
  1220.    are careful not to change the C type of the overall expression)
  1221.    We cannot simplify through a CONVERT_EXPR, FIX_EXPR or FLOAT_EXPR,
  1222.    but we can constant-fold them if they have constant operands.  */
  1223.  
  1224. tree
  1225. fold (expr) 
  1226.      tree expr;
  1227. {
  1228.   register tree t = expr;
  1229.   tree type = TREE_TYPE (expr);
  1230.   register tree arg0, arg1;
  1231.   register enum tree_code code = TREE_CODE (t);
  1232.   register int kind;
  1233.  
  1234.   /* WINS will be nonzero when the switch is done
  1235.      if all operands are constant.
  1236.  
  1237.      LOSES will be nonzero when the switch is done
  1238.      if any operand is volatile.
  1239.      This inhibits optimizations such as  (foo () * 0) => 0.
  1240.      But identity-element optimizations such as
  1241.      (foo () * 1) => (foo ()) can be done even if LOSES is set.  */
  1242.  
  1243.   int wins = 1;
  1244.   int loses = 0;
  1245.  
  1246.   /* Return right away if already constant.  */
  1247.   if (TREE_LITERAL (t))
  1248.     {
  1249.       if (code == CONST_DECL)
  1250.     return DECL_INITIAL (t);
  1251.       return t;
  1252.     }
  1253.   
  1254.   kind = *tree_code_type[(int) code];
  1255.   if (kind == 'e' || kind == 'r')
  1256.     {
  1257.       register int len = tree_code_length[(int) code];
  1258.       register int i;
  1259.       for (i = 0; i < len; i++)
  1260.     {
  1261.       if (TREE_OPERAND (t, i) == 0)
  1262.         continue;        /* Valid for CALL_EXPR, at least.  */
  1263.       if (TREE_CODE (TREE_OPERAND (t, i)) != INTEGER_CST
  1264. #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1265.           && TREE_CODE (TREE_OPERAND (t, i)) != REAL_CST
  1266. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1267.           )
  1268.         /* Note that TREE_LITERAL isn't enough:
  1269.            static var addresses are constant but we can't
  1270.            do arithmetic on them.  */
  1271.         wins = 0;
  1272.       if (TREE_VOLATILE (TREE_OPERAND (t, i)))
  1273.         loses = 1;
  1274.     }
  1275.       arg0 = TREE_OPERAND (t, 0);
  1276.       if (len > 1)
  1277.     arg1 = TREE_OPERAND (t, 1);
  1278.     }
  1279.  
  1280.   /* Now WINS and LOSES are set as described above,
  1281.      ARG0 is the first operand of EXPR,
  1282.      and ARG1 is the second operand (if it has more than one operand).  */
  1283.  
  1284.   switch (code)
  1285.     {
  1286.     case INTEGER_CST:
  1287.     case REAL_CST:
  1288.     case STRING_CST:
  1289.     case COMPLEX_CST:
  1290.     case CONSTRUCTOR:
  1291.       return t;
  1292.  
  1293.     case CONST_DECL:
  1294.       return fold (DECL_INITIAL (t));
  1295.  
  1296.     case NOP_EXPR:
  1297.     case FLOAT_EXPR:
  1298.     case CONVERT_EXPR:
  1299.     case FIX_TRUNC_EXPR:
  1300.       /* Other kinds of FIX are not handled properly by fold_convert.  */
  1301.       if (!wins)
  1302.     {
  1303.       TREE_LITERAL (t) = TREE_LITERAL (arg0);
  1304.       return t;
  1305.     }
  1306.       return fold_convert (t);
  1307.  
  1308. #if 0  /* This loses on &"foo"[0].  */
  1309.     case ARRAY_REF:
  1310.     {
  1311.       int i;
  1312.  
  1313.       /* Fold an expression like: "foo"[2] */
  1314.       if (TREE_CODE (arg0) == STRING_CST
  1315.           && TREE_CODE (arg1) == INTEGER_CST
  1316.           && !TREE_INT_CST_HIGH (arg1)
  1317.           && (i = TREE_INT_CST_LOW (arg1)) < TREE_STRING_LENGTH (arg0))
  1318.         {
  1319.           t = build_int_2 (TREE_STRING_POINTER (arg0)[i], 0);
  1320.           TREE_TYPE (t) = TREE_TYPE (TREE_TYPE (arg0));
  1321.           force_fit_type (t);
  1322.         }
  1323.     }
  1324.       return t;
  1325. #endif /* 0 */
  1326.  
  1327.     case RANGE_EXPR:
  1328.       TREE_LITERAL (t) = wins;
  1329.       return t;
  1330.  
  1331.     case NEGATE_EXPR:
  1332.       if (wins)
  1333.     {
  1334.       if (TREE_CODE (arg0) == INTEGER_CST)
  1335.         {
  1336.           if (TREE_INT_CST_LOW (arg0) == 0)
  1337.         t = build_int_2 (0, - TREE_INT_CST_HIGH (arg0));
  1338.           else
  1339.         t = build_int_2 (- TREE_INT_CST_LOW (arg0),
  1340.                  ~ TREE_INT_CST_HIGH (arg0));
  1341.           TREE_TYPE (t) = type;
  1342.           force_fit_type (t);
  1343.         }
  1344.       else if (TREE_CODE (arg0) == REAL_CST)
  1345.         t = build_real (type, REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
  1346.       TREE_TYPE (t) = type;
  1347.     }
  1348.       return t;
  1349.  
  1350.     case ABS_EXPR:
  1351.       if (wins)
  1352.     {
  1353.       if (TREE_CODE (arg0) == INTEGER_CST)
  1354.         {
  1355.           if (! TREE_UNSIGNED (type)
  1356.           && TREE_INT_CST_HIGH (arg0) < 0)
  1357.         {
  1358.           if (TREE_INT_CST_LOW (arg0) == 0)
  1359.             t = build_int_2 (0, - TREE_INT_CST_HIGH (arg0));
  1360.           else
  1361.             t = build_int_2 (- TREE_INT_CST_LOW (arg0),
  1362.                      ~ TREE_INT_CST_HIGH (arg0));
  1363.         }
  1364.         }
  1365.       else if (TREE_CODE (arg0) == REAL_CST)
  1366.         {
  1367.           if (
  1368. #if defined (REAL_IS_NOT_DOUBLE)
  1369.           REAL_VALUES_LESS (TREE_REAL_CST (arg0),
  1370.                     REAL_VALUE_ATOF ("0.0"))
  1371. #else
  1372.           REAL_VALUES_LESS (TREE_REAL_CST (arg0), 0)
  1373. #endif
  1374.           )
  1375.         t = build_real (type,
  1376.                 REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
  1377.         }
  1378.       TREE_TYPE (t) = type;
  1379.     }
  1380.       return t;
  1381.  
  1382.     case BIT_NOT_EXPR:
  1383.       if (wins)
  1384.     {
  1385.       if (TREE_CODE (arg0) == INTEGER_CST)
  1386.         t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
  1387.                  ~ TREE_INT_CST_HIGH (arg0));
  1388.       TREE_TYPE (t) = type;
  1389.       force_fit_type (t);
  1390.     }
  1391.       return t;
  1392.  
  1393.     case PLUS_EXPR:
  1394.       if (integer_zerop (arg0))
  1395.     return convert (type, arg1);
  1396.       if (integer_zerop (arg1))
  1397.     return convert (type, arg0);
  1398.     associate:
  1399.       /* In most languages, can't associate operations on floats
  1400.      through parentheses.  Rather than remember where the parentheses
  1401.      were, we don't associate floats at all.  It shouldn't matter much.  */
  1402.       if (TREE_CODE (type) == REAL_TYPE)
  1403.     goto binary;
  1404.       /* The varsign == -1 cases happen only for addition and subtraction.
  1405.      It says that the arg that was split was really CON minus VAR.
  1406.      The rest of the code applies to all associative operations.  */
  1407.       if (!wins)
  1408.     {
  1409.       tree var, con, tem;
  1410.       int varsign;
  1411.  
  1412.       if (split_tree (arg0, code, &var, &con, &varsign))
  1413.         {
  1414.           if (varsign == -1)
  1415.         {
  1416.           /* EXPR is (CON-VAR) +- ARG1.  */
  1417.           /* If it is + and VAR==ARG1, return just CONST.  */
  1418.           if (code == PLUS_EXPR && operand_equal_p (var, arg1))
  1419.             return convert (TREE_TYPE (t), con);
  1420.             
  1421.           /* Otherwise return (CON +- ARG1) - VAR.  */
  1422.           TREE_SET_CODE (t, MINUS_EXPR);
  1423.           TREE_OPERAND (t, 1) = var;
  1424.           TREE_OPERAND (t, 0)
  1425.             = fold (build (code, TREE_TYPE (t), con, arg1));
  1426.         }
  1427.           else
  1428.         {
  1429.           /* EXPR is (VAR+CON) +- ARG1.  */
  1430.           /* If it is - and VAR==ARG1, return just CONST.  */
  1431.           if (code == MINUS_EXPR && operand_equal_p (var, arg1))
  1432.             return convert (TREE_TYPE (t), con);
  1433.             
  1434.           /* Otherwise return VAR +- (ARG1 +- CON).  */
  1435.           TREE_OPERAND (t, 1) = tem
  1436.             = fold (build (code, TREE_TYPE (t), arg1, con));
  1437.           TREE_OPERAND (t, 0) = var;
  1438.           if (integer_zerop (tem)
  1439.               && (code == PLUS_EXPR || code == MINUS_EXPR))
  1440.             return var;
  1441.           /* If we have x +/- (c - d) [c an explicit integer]
  1442.              change it to x -/+ (d - c) since if d is relocatable
  1443.              then the latter can be a single immediate insn
  1444.              and the former cannot.  */
  1445.           if (TREE_CODE (tem) == MINUS_EXPR
  1446.               && TREE_CODE (TREE_OPERAND (tem, 0)) == INTEGER_CST)
  1447.             {
  1448.               tree tem1 = TREE_OPERAND (tem, 1);
  1449.               TREE_OPERAND (tem, 1) = TREE_OPERAND (tem, 0);
  1450.               TREE_OPERAND (tem, 0) = tem1;
  1451.               TREE_SET_CODE (t,
  1452.                      (code == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR));
  1453.             }
  1454.         }
  1455.           return t;
  1456.         }
  1457.  
  1458.       if (split_tree (arg1, code, &var, &con, &varsign))
  1459.         {
  1460.           /* EXPR is ARG0 +- (CON +- VAR).  */
  1461.           if (varsign == -1)
  1462.         TREE_SET_CODE (t,
  1463.                    (code == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR));
  1464.           if (TREE_CODE (t) == MINUS_EXPR && operand_equal_p (var, arg0))
  1465.         return convert (TREE_TYPE (t), con);
  1466.           TREE_OPERAND (t, 0)
  1467.         = fold (build (code, TREE_TYPE (t), arg0, con));
  1468.           TREE_OPERAND (t, 1) = var;
  1469.           if (integer_zerop (TREE_OPERAND (t, 0))
  1470.           && TREE_CODE (t) == PLUS_EXPR)
  1471.         return convert (TREE_TYPE (t), var);
  1472.           return t;
  1473.         }
  1474.     }
  1475.     binary:
  1476. #if defined (REAL_IS_NOT_DOUBLE) && ! defined (REAL_ARITHMETIC)
  1477.       if (TREE_CODE (arg1) == REAL_CST)
  1478.     return t;
  1479. #endif /* REAL_IS_NOT_DOUBLE, and no REAL_ARITHMETIC */
  1480.       {
  1481.     register tree t1 = NULL_TREE;
  1482.     if (wins)
  1483.       t1 = combine (code, arg0, arg1);
  1484.     if (t1 != NULL_TREE) return t1;
  1485.     return t;
  1486.       }
  1487.  
  1488.     case MINUS_EXPR:
  1489.       if (! wins && integer_zerop (arg0))
  1490.     return build (NEGATE_EXPR, type, arg1);
  1491.       if (integer_zerop (arg1))
  1492.     return convert (type, arg0);
  1493.       /* Fold &x - &x.  This can happen from &x.foo - &x.  */
  1494.       if (operand_equal_p (arg0, arg1))
  1495.     return convert (TREE_TYPE (t), integer_zero_node);
  1496.       goto associate;
  1497.  
  1498.     case MULT_EXPR:
  1499.       if (!loses && integer_zerop (arg0))
  1500.     return convert (type, arg0);
  1501.       if (!loses && integer_zerop (arg1))
  1502.     return convert (type, arg1);
  1503.       if (integer_onep (arg0))
  1504.     return convert (type, arg1);
  1505.       if (integer_onep (arg1))
  1506.     return convert (type, arg0);
  1507.       goto associate;
  1508.  
  1509.     case BIT_IOR_EXPR:
  1510.       if (!loses && integer_all_onesp (arg0))
  1511.     return convert (type, arg0);
  1512.       if (!loses && integer_all_onesp (arg1))
  1513.     return convert (type, arg1);
  1514.     case BIT_XOR_EXPR:
  1515.       if (integer_zerop (arg0))
  1516.     return convert (type, arg1);
  1517.       if (integer_zerop (arg1))
  1518.     return convert (type, arg0);
  1519.       goto associate;
  1520.  
  1521.     case BIT_AND_EXPR:
  1522.       if (integer_all_onesp (arg0))
  1523.     return convert (type, arg1);
  1524.       if (integer_all_onesp (arg1))
  1525.     return convert (type, arg0);
  1526.       if (!loses && integer_zerop (arg0))
  1527.     return convert (type, arg0);
  1528.       if (!loses && integer_zerop (arg1))
  1529.     return convert (type, arg1);
  1530.       /* Simplify ((int)c & 0x377) into (int)c, if c is unsigned char.  */
  1531.       if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == NOP_EXPR
  1532.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg1, 0))))
  1533.     {
  1534.       int prec = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 0)));
  1535.       if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_INT
  1536.           && (~TREE_INT_CST_LOW (arg0) & ((1 << prec) - 1)) == 0)
  1537.         return build (NOP_EXPR, type, TREE_OPERAND (arg1, 0));
  1538.     }
  1539.       if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR
  1540.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
  1541.     {
  1542.       int prec = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)));
  1543.       if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_INT
  1544.           && (~TREE_INT_CST_LOW (arg1) & ((1 << prec) - 1)) == 0)
  1545.         return build (NOP_EXPR, type, TREE_OPERAND (arg0, 0));
  1546.     }
  1547.       goto associate;
  1548.  
  1549.     case BIT_ANDTC_EXPR:
  1550.       if (integer_all_onesp (arg0))
  1551.     return convert (type, arg1);
  1552.       if (integer_zerop (arg1))
  1553.     return convert (type, arg0);
  1554.       if (!loses && integer_zerop (arg0))
  1555.     return convert (type, arg0);
  1556.       if (!loses && integer_all_onesp (arg1))
  1557.     return combine (code, arg1, arg1);
  1558.       goto binary;
  1559.  
  1560.     case TRUNC_DIV_EXPR:
  1561.     case ROUND_DIV_EXPR:
  1562.     case FLOOR_DIV_EXPR:
  1563.     case CEIL_DIV_EXPR:
  1564.     case EXACT_DIV_EXPR:
  1565.     case RDIV_EXPR:
  1566.       if (integer_onep (arg1))
  1567.     return convert (type, arg0);
  1568.       if (integer_zerop (arg1))
  1569.     return t;
  1570. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1571.       if (TREE_CODE (arg1) == REAL_CST
  1572.       && real_zerop (arg1))
  1573.     return t;
  1574. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1575.  
  1576.       goto binary;
  1577.  
  1578.     case CEIL_MOD_EXPR:
  1579.     case FLOOR_MOD_EXPR:
  1580.     case ROUND_MOD_EXPR:
  1581.     case TRUNC_MOD_EXPR:
  1582.       if (!loses && integer_onep (arg1))
  1583.     return combine (code, arg1, arg1);
  1584.       if (integer_zerop (arg1))
  1585.     return t;
  1586.       goto binary;
  1587.  
  1588.     case LSHIFT_EXPR:
  1589.     case RSHIFT_EXPR:
  1590.     case LROTATE_EXPR:
  1591.     case RROTATE_EXPR:
  1592.       if (integer_zerop (arg1))
  1593.     return convert (type, arg0);
  1594.       goto binary;
  1595.  
  1596.     case MIN_EXPR: case MAX_EXPR:
  1597.       goto associate;
  1598.  
  1599.     case TRUTH_NOT_EXPR:
  1600.       /* Note that the operand of this must be an int
  1601.      and its values must be 0 or 1.
  1602.      ("true" is a fixed value perhaps depending on the language,
  1603.      but we don't handle values other than 1 correctly yet.)  */
  1604.       if (TREE_CODE (arg0) == INTEGER_CST)
  1605.     {
  1606.       t = build_int_2 ((TREE_INT_CST_LOW (arg0) == 0
  1607.                 && TREE_INT_CST_HIGH (arg0) == 0),
  1608.                0);
  1609.       TREE_TYPE (t) = integer_type_node;
  1610.     }
  1611.       return t;
  1612.  
  1613.     case TRUTH_ANDIF_EXPR:
  1614.       /* Note that the operands of this must be ints
  1615.      and their values must be 0 or 1.
  1616.      ("true" is a fixed value perhaps depending on the language.)  */
  1617.       /* If first arg is constant zero, return it.  */
  1618.       if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
  1619.     return arg0;
  1620.     case TRUTH_AND_EXPR:
  1621.       /* If either arg is constant true, drop it.  */
  1622.       if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
  1623.     return arg1;
  1624.       if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
  1625.     return arg0;
  1626.       /* Both known to be zero => return zero.  */
  1627.       if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
  1628.     return arg0;
  1629.       return t;
  1630.  
  1631.     case TRUTH_ORIF_EXPR:
  1632.       /* Note that the operands of this must be ints
  1633.      and their values must be 0 or true.
  1634.      ("true" is a fixed value perhaps depending on the language.)  */
  1635.       /* If first arg is constant true, return it.  */
  1636.       if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
  1637.     return arg0;
  1638.     case TRUTH_OR_EXPR:
  1639.       /* If either arg is constant zero, drop it.  */
  1640.       if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
  1641.     return arg1;
  1642.       if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1))
  1643.     return arg0;
  1644.       /* Both known to be true => return true.  */
  1645.       if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
  1646.     return arg0;
  1647.       return t;
  1648.  
  1649.     case EQ_EXPR:
  1650.     case NE_EXPR:
  1651.     case LT_EXPR:
  1652.     case GT_EXPR:
  1653.     case LE_EXPR:
  1654.     case GE_EXPR:
  1655.       /* If one arg is a constant integer, put it last.  */
  1656.       if (TREE_CODE (arg0) == INTEGER_CST
  1657.       && TREE_CODE (arg1) != INTEGER_CST)
  1658.     {
  1659.       TREE_OPERAND (t, 0) = arg1;
  1660.       TREE_OPERAND (t, 1) = arg0;
  1661.       arg0 = TREE_OPERAND (t, 0);
  1662.       arg1 = TREE_OPERAND (t, 1);
  1663.       switch (code)
  1664.         {
  1665.         case GT_EXPR:
  1666.           code = LT_EXPR;
  1667.           break;
  1668.         case GE_EXPR:
  1669.           code = LE_EXPR;
  1670.           break;
  1671.         case LT_EXPR:
  1672.           code = GT_EXPR;
  1673.           break;
  1674.         case LE_EXPR:
  1675.           code = GE_EXPR;
  1676.           break;
  1677.         }
  1678.       TREE_SET_CODE (t, code);
  1679.     }
  1680.  
  1681.       /* Convert foo++ == CONST into ++foo == CONST + INCR.
  1682.      First, see if one arg is constant; find the constant arg
  1683.      and the other one.  */
  1684.       {
  1685.     tree constop = 0, varop;
  1686.     tree *constoploc;
  1687.  
  1688.     if (TREE_LITERAL (arg1))
  1689.       constoploc = &TREE_OPERAND (t, 1), constop = arg1, varop = arg0;
  1690.     if (TREE_LITERAL (arg0))
  1691.       constoploc = &TREE_OPERAND (t, 0), constop = arg0, varop = arg1;
  1692.  
  1693.     if (constop && TREE_CODE (varop) == POSTINCREMENT_EXPR)
  1694.       {
  1695.         tree newconst
  1696.           = fold (build (PLUS_EXPR, TREE_TYPE (constop),
  1697.                  constop, TREE_OPERAND (varop, 1)));
  1698.         /* This optimization is invalid for ordered comparisons
  1699.            if CONST+INCR overflows or if foo+incr might overflow.
  1700.            For pointer types we assume overflow doesn't happen.  */
  1701.         if (TREE_CODE (TREE_TYPE (varop)) == POINTER_TYPE
  1702.         || code == EQ_EXPR || code == NE_EXPR)
  1703.           {
  1704.         TREE_SET_CODE (varop, PREINCREMENT_EXPR);
  1705.         *constoploc = newconst;
  1706.         return t;
  1707.           }
  1708.       }
  1709.     else if (constop && TREE_CODE (varop) == POSTDECREMENT_EXPR)
  1710.       {
  1711.         tree newconst
  1712.           = fold (build (MINUS_EXPR, TREE_TYPE (constop),
  1713.                  constop, TREE_OPERAND (varop, 1)));
  1714.         if (TREE_CODE (TREE_TYPE (varop)) == POINTER_TYPE
  1715.         || code == EQ_EXPR || code == NE_EXPR)
  1716.           {
  1717.         TREE_SET_CODE (varop, PREDECREMENT_EXPR);
  1718.         *constoploc = newconst;
  1719.         return t;
  1720.           }
  1721.       }
  1722.       }
  1723.  
  1724.       /* Change X >= CST to X > (CST - 1) if CST is positive.  */
  1725.       if (TREE_CODE (arg1) == INTEGER_CST
  1726.       && TREE_CODE (arg0) != INTEGER_CST
  1727.       && ! tree_int_cst_lt (arg1, integer_one_node))
  1728.     {
  1729.       switch (TREE_CODE (t))
  1730.         {
  1731.         case GE_EXPR:
  1732.           code = GT_EXPR;
  1733.           TREE_SET_CODE (t, code);
  1734.           arg1 = combine (MINUS_EXPR, arg1, integer_one_node);
  1735.           TREE_OPERAND (t, 1) = arg1;
  1736.           break;
  1737.  
  1738.         case LT_EXPR:
  1739.           code = LE_EXPR;
  1740.           TREE_SET_CODE (t, code);
  1741.           arg1 = combine (MINUS_EXPR, arg1, integer_one_node);
  1742.           TREE_OPERAND (t, 1) = arg1;
  1743.         }
  1744.     }
  1745.  
  1746.       /* An unsigned comparison against 0 can be simplified.  */
  1747.       if (integer_zerop (arg1)
  1748.       && (TREE_CODE (TREE_TYPE (arg1)) == INTEGER_TYPE
  1749.           || TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE)
  1750.       && TREE_UNSIGNED (TREE_TYPE (arg1)))
  1751.     {
  1752.       switch (TREE_CODE (t))
  1753.         {
  1754.         case GT_EXPR:
  1755.           TREE_SET_CODE (t, NE_EXPR);
  1756.           break;
  1757.         case LE_EXPR:
  1758.           TREE_SET_CODE (t, EQ_EXPR);
  1759.           break;
  1760.         case GE_EXPR:
  1761.           return build (COMPOUND_EXPR, integer_type_node,
  1762.                 arg0, integer_one_node);
  1763.         case LT_EXPR:
  1764.           return build (COMPOUND_EXPR, integer_type_node,
  1765.                 arg0, integer_zero_node);
  1766.         }
  1767.     }
  1768.  
  1769.       /* To compute GT, swap the arguments and do LT.
  1770.      To compute GE, do LT and invert the result.
  1771.      To compute LE, swap the arguments, do LT and invert the result.
  1772.      To compute NE, do EQ and invert the result.  */
  1773.       if (code == LE_EXPR || code == GT_EXPR)
  1774.     {
  1775.       register tree temp = arg0;
  1776.       arg0 = arg1;
  1777.       arg1 = temp;
  1778.     }
  1779.  
  1780.       /* Compute a result for LT or EQ if args permit;
  1781.      otherwise return T.  */
  1782.       if (TREE_CODE (arg0) == INTEGER_CST
  1783.       && TREE_CODE (arg1) == INTEGER_CST)
  1784.     {
  1785.       if (code == EQ_EXPR || code == NE_EXPR)
  1786.         t = build_int_2
  1787.           (TREE_INT_CST_LOW (arg0) == TREE_INT_CST_LOW (arg1)
  1788.            && TREE_INT_CST_HIGH (arg0) == TREE_INT_CST_HIGH (arg1),
  1789.            0);
  1790.       else
  1791.         t = build_int_2 ((TREE_UNSIGNED (TREE_TYPE (arg0))
  1792.                   ? INT_CST_LT_UNSIGNED (arg0, arg1)
  1793.                   : INT_CST_LT (arg0, arg1)),
  1794.                  0);
  1795.     }
  1796.       else if (TREE_CODE (arg1) == INTEGER_CST
  1797.            && TREE_LITERAL (arg0)
  1798.            && TREE_CODE (arg0) == ADDR_EXPR
  1799.            && (code == EQ_EXPR || code == NE_EXPR))
  1800.     {
  1801.       t = build_int_2 (0, 0);
  1802.     }
  1803.       else if (TREE_CODE (arg0) == REAL_CST
  1804.            && TREE_CODE (arg1) == REAL_CST)
  1805.     {
  1806.       if (code == EQ_EXPR || code == NE_EXPR)
  1807.         t = build_int_2 (REAL_VALUES_EQUAL (TREE_REAL_CST (arg0),
  1808.                         TREE_REAL_CST (arg1)),
  1809.                  0);
  1810.       else
  1811.         t = build_int_2 (REAL_VALUES_LESS (TREE_REAL_CST (arg0),
  1812.                            TREE_REAL_CST (arg1)),
  1813.                  0);
  1814.     }
  1815.       else
  1816.     return t;
  1817.  
  1818.       /* If what we want is other than LT or EQ, invert the result.  */
  1819.       if (code == GE_EXPR || code == LE_EXPR || code == NE_EXPR)
  1820.     TREE_INT_CST_LOW (t) ^= 1;
  1821.       TREE_TYPE (t) = type;
  1822.       return t;
  1823.  
  1824.     case COND_EXPR:
  1825.       if (TREE_LITERAL (arg0))
  1826.     return TREE_OPERAND (expr, (integer_zerop (arg0) ? 2 : 1));
  1827.       return t;
  1828.  
  1829.     default:
  1830.       return t;
  1831.     } /* switch (code) */
  1832. }
  1833.